//
//  DECXWarehouseChargeViewController.m
//  DECXInStore
//
//  Created by 李坤 on 2019/12/16.
//  Copyright © 2019 程强. All rights reserved.
//

#import "DECXWarehouseChargeViewController.h"
#import "DECXWarehouseChargeManager.h"
#import "DECXChargeTableCell.h"
#import "DECXChargeDetailsObj.h"

@interface DECXWarehouseChargeViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *chargeTable;
@property (strong, nonatomic) DECXWarehouseChargeManager *manager;
@property (strong, nonatomic) DECXChargeDetailsObj *chargeData;
@end

@implementation DECXWarehouseChargeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    self.view.backgroundColor = [UIColor whiteColor];
    self.manager = [DECXWarehouseChargeManager  new];
    [self fetchChargeDetails];
}
- (void)setupUI
{
    [self.chargeTable registerClass:[DECXChargeTableCell class] forCellReuseIdentifier:@"ChargeCell"];
}
- (void)fetchChargeDetails
{
    weak_Self(self);
    [self showHUD];
    [[self.manager getOrderChargeDetails:self.order_id]subscribeNext:^(id x) {
        weakSelf.chargeData = x;
        [weakSelf.chargeTable reloadData];
        [weakSelf hideHUD];
    } error:^(NSError *error) {
        NSString *msg = error.userInfo[@"msg"];
        [weakSelf showMessageHUD:msg delayHide:1.0];
    } completed:^{
        
    }];
}
#pragma mark --- TableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.chargeData.list.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 150.0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *indentifier = @"ChargeCell";
    DECXChargeTableCell *cell = [tableView dequeueReusableCellWithIdentifier:indentifier];
    if (!cell) {
        cell = [[DECXChargeTableCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indentifier];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    DECXChargeModel *model = self.chargeData.list[indexPath.row];
    cell.dateLbl.text = model.date;
    cell.sumLbl.text = [NSString stringWithFormat:@"￥%@",model.sum];
    cell.priceLbl.text = [NSString stringWithFormat:@"￥%@/天",model.price];
    cell.countLbl.text = [NSString stringWithFormat:@"%@吨",model.num];
    cell.markLbl.text = model.msg;
    return cell;
}

@end
